<template>
    <div class="wrapper" style="box-sizing:border-box;">
        
        <v-head ref='setUser'></v-head>
        <div style="width: 100%;" id='content2'>
	        <div class="content2" v-if="peopleListT&&systemListT&&uidT">
	            <transition name="move" mode="out-in"><router-view  ></router-view></transition>
	        </div>
        </div>
       
    </div>
</template>

<script>
    import vHead from './Header.vue';
    import vFooter from './footer.vue';
    import Vue from 'vue';
    import { Toast } from 'mint-ui';
    import wx from 'weixin-js-sdk';
   
    export default {
        components:{
            vHead,vFooter
        },
        beforcreated(){
        	
        },
        data(){
            return{
            	systemListT:false,
            	peopleListT:false,
            	uidT:false,
            }
        },
        mounted(){
           
			Vue.prototype.Toast=function(options){
				Toast(options);
			};
			
			this.get_uid();
        },
        methods:{
        	get_uid(){
        		if(window.location.href.indexOf('reg_invitation_code=') > -1){
        			let model = window.location.href.substring(window.location.href.indexOf('?') + 1, window.location.href.length)
        			location.href = 'http://api.jiangzuoyoupin.com/api/login?'+model;
        			return false;
        		}
        		let uid_html = localStorage.getItem("uid");
        		if(window.location.href.indexOf('member_id=') > -1 || uid_html) {
					if(window.location.href.indexOf('member_id=') > -1){
						console.log(1);
						window.uid = window.location.href.substring(window.location.href.indexOf('member_id=') + 10, window.location.href.length);
						localStorage.setItem("uid",window.uid);
						
					}
					else{
						window.uid=uid_html;
						
					}
					console.log(window.uid)
					this.get_parame();
					this.get_member_info();
					this.get_wechat_param();
					this.uidT=true;
					
				} else {
					
					if(window.uid) {
						this.uidT=true;
						this.get_parame();
						this.get_member_info();
						this.get_wechat_param();
					} else {
						location.href = 'http://api.jiangzuoyoupin.com/api/login'
					}
				}
        	},
        	wxconfig(data){
        		wx.config({
				    debug: false,
				    appId: data.appId, // 和获取Ticke的必须一样------必填，公众号的唯一标识
				    timestamp:data.timestamp, // 必填，生成签名的时间戳
				    nonceStr: data.nonceStr, // 必填，生成签名的随机串
				    signature: data.signature,// 必填，签名，见附录1
				    //需要分享的列表项:发送给朋友，分享到朋友圈
				    jsApiList: [
						'onMenuShareTimeline',//分享给好友
                    	'onMenuShareAppMessage'//分享到朋友圈
					]
				});
				
				
				
				
        	},
        	
        	get_wechat_param(){
        		this.ajax(this, {
					'url': this.defines.get_wechat_param,
					'type': 'post',
					'data':{
						'url':window.location.href.split('#')[0]
					},
					'callback': data => {
						if(data.data.error_code==0) {
							console.log(data);
							
							this.wxconfig(data.data.data);
						} else {
							
						}
						

					},
					'errorback': errory => {

					},

				})
        	},
        	get_parame(){
        		this.ajax(this, {
					'url': this.defines.get_parame,
					'type': 'get',
					'callback': data => {
						if(data.data.error_code==0) {
							Vue.prototype.systemList=data.data.data;
							this.systemListT=true;
							
						} else {
							
						}
						if(data.data.error_code==1001) {
							location.href = 'http://api.jiangzuoyoupin.com/api/login';
							
						}

					},
					'errorback': errory => {

					},

				})
        	},
        	get_member_info(){
        		this.ajax(this, {
					'url': this.defines.get_member_info,
					'type': 'post',
					'data':{
						'member_id':window.uid,
					},
					'callback': data => {
						if(data.data.error_code==0) {
							Vue.prototype.peopleList=data.data.data;
							this.peopleListT=true;
						} else {
							this.Toast(data.data.error_msg)
						}
						if(data.data.error_code==1001) {
							location.href = 'http://api.jiangzuoyoupin.com/api/login';
							
						}

					},
					'errorback': errory => {

					},

				})
        	}
        }
    }
</script>
<style>
	
</style>
